<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'门店列表'),
);
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$worker=pdo_get('jy_yxw_worker',array('id'=>$_SESSION['workerid'],'uniacid'=>$_SESSION['uniacid']));
	$storeidlist=str_array($worker['storeidlist']);
	if(!$storeidlist){
		$storeidlist=-1;
	}
	$params['id']=$storeidlist;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','title','address','type','status','tel','pcd','logo');
	$list=pdo_getslice('jy_yxw_store',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
				$item['number']='NO'.sprintf("%06d", $item['id']);
				$item['pcd']=json_decode($item['pcd'],true);
				$item['address']=$item['pcd']['province'].' '.$item['pcd']['city'].' '.$item['pcd']['district'].' '.$item['pcd']['street'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('tip'=>'温馨提示：
		</br>1、这里显示所有我可以查看的门店！
		','data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'门店名称','type'=>'string'),
			array('name'=>'logo','title'=>'门店logo','type'=>'image'),
			array('name'=>'tel','title'=>'电话','type'=>'string'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
		),'action'=>array(
			array('type'=>'href','action'=>'jy_yxw/role15.list/tostore/','title'=>'前往该门店>>'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'门店名称','name'=>'title','help'=>''),
		)
	);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='tostore'){
	$id=intval($_RQ['id']);
	if($id){
		$store=pdo_get('jy_yxw_store',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$_SESSION['store_type']=$store['type'];
		$url='/store.index/';
		if($_SESSION['store_type']==1){
			$url='/jiaoxue.index/';
		}
		$_SESSION['storeid']=$id;
		$_SESSION['istostore']=1;
		exi('','',custom_url($url,true));
	}else{
		exi('请选择门店','error');
	}
}